package com.bsoft.controller;

import com.bsoft.producer.Demo5producer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CountDownLatch;

@Slf4j
@RestController
public class Demo05Controller {
    @Autowired
    private Demo5producer demo5producer;

    @GetMapping("/batchProductor")
    public void testSynSend() throws InterruptedException {
        for (int i = 0; i < 3; i++) {
            // 同步发送消息
            int id = (int) (System.currentTimeMillis() / 1000);
            demo5producer.syncSend(id);

            // 故意每条消息之间，隔离 10 秒
            log.info("[testSyncSend][发送编号：[{}] 发送成功]", id);
//
        }
        Thread.sleep(10 * 1000L);
        // 阻塞等待，保证消费
        new CountDownLatch(1).await();
    }
}
